//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
     items: [
          { name: '日常疾病和健康咨询', value: '日常疾病和健康咨询', checked: false},
          { name: '可根据病情提供就诊前/就诊后指导', value: '可根据病情提供就诊前/就诊后指导', checked: false },
          { name: '可根据病情提供住院前/住院后指代', value: '可根据病情提供住院前/住院后指代', checked: false},
          { name: '可根据病情提供术前/术后指代', value: '可根据病情提供术前/术后指代', checked: false},
          { name: '诊后治疗和康复相关问题', value: '诊后治疗和康复相关问题', checked: false},
       { name: '其他', value: '其他', checked: false, textarea: ""}
     ],
    citems: [
      { name: '已读并同意购买须知', value: '已读并同意购买须知', checked: false }
    ],
    indexnum:0,
    textkey:false,
    trandata:[]
  },
  //多选框   
     checkboxChange: function (e) {
          console.log('checkbox发生change事件，携带value值为：', e.detail.value)
      //  wx.setStorageSync('help', e.detail.value)
       if (e.detail.value.length>=3){
            wx.showToast({
              title: '最多选择三项',
              icon:'none',
              mask:true
            })
          }
        },
     changeitem:function(e){
       let index = e.currentTarget.dataset.index
       let checked = `items[${index}].checked`
       this.setData({
         [checked]: !this.data.items[index].checked
       })
       if (this.data.items[5].checked==true){
         console.log(1212000)
          this.setData({
            textkey: true
          })
        }else{
            this.setData({
              textkey: false
            })
        }
     },

  //协议
    checkboxChanges: function (e) {
    console.log('checkbox发生change事件，携带value值为：', e.detail.value)
  },
  changeitems:function(){
    let checked = `citems[0].checked`
    this.setData({
      [checked]: !this.data.citems[0].checked
    })
  },
  //获取文本框
  getext:function(e){
    let textarea =`items[5].textarea`
    this.setData({
      [textarea]: e.detail.value
    })
  },
  //下一步
  nextpage:function(){
    let item = this.data.items
  
    if (this.data.citems[0].checked == false) {
      wx.showToast({
        title: '请同意协议',
        icon: "none",
        mask: true
      })
      return false
    } 
    
      for (let i = 0; i < item.length; i++) {
        if (item[i].checked == true) {
          wx.setStorageSync('items', this.data.items)
          
          wx.navigateTo({
            url: '/hyb_yl/czhuanjiasubpages/pages/perdocinfo/index'
          })
          return false
        } else {
          wx.showToast({
            title: '请选择您希望得到的帮助',
            icon: 'none'
          })
        }
    }


    
    
  },

  onLoad: function () {
    
  }
  
})
